<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Woreport_model extends CI_Model {
	public function __construct() {
		parent::__construct();
	}
	
	public function get_status($date,$stat){
		$where = '';
		if(!empty($date) && empty($stat)){
			$where = " WHERE DATE_FORMAT(uwo.actual_completion_date,'%Y-%m') = '".$date."'";
		}
		if(!empty($stat) && empty($date)){
			$where = " WHERE maintain_code = '". $stat."'";
		}
		if(!empty($date) && !empty($stat)){
			$where = " WHERE DATE_FORMAT(uwo.actual_completion_date,'%Y-%m') = '".$date."' AND maintain_code = '". $stat."'";
		} 
		if(empty($date) && empty($stat)){
			$where = "";
		}

		$q = $this->db->query("SELECT uwo.status,uwo.actual_completion_date, uwo.target_date, uwo.status, uwo.last_meter_reading, uwo.new_meter_reading, alv.meaning, aa.acct_name, aa.acct_num,au.user_name assign_by, au1.user_name comp_by FROM ubs_work_order uwo
							INNER JOIN ar_account aa ON uwo.account_id = aa.account_id
						    INNER JOIN app_users au ON au.user_id = uwo.assigned_to
						    INNER JOIN app_users au1 ON au1.user_id = uwo.completed_by
						    INNER JOIN app_lookup_values alv ON alv.lookup_type = 'UBS_MAINTAIN_TYPE' AND alv.lookup_code = uwo.maintain_code".$where);
		return $q->result();
	}

	public function get_maintain_type() {
		$sql = "SELECT * FROM app_lookup_values WHERE lookup_type = 'UBS_MAINTAIN_TYPE'";
		$query = $this->db->query($sql);
		return $query->result();
	}
	
}